package com.woniuxy.micromallserver.task;

import com.woniuxy.micromallserver.ordermag.service.IOrderService;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author unreleased
 * @date 2021/1/30 15:59
 */
@Component
@EnableScheduling
public class WebSocketTask {
    @Resource
    SimpMessagingTemplate template;
    @Resource
    private IOrderService orderServiceImpl;

    @Scheduled(cron="0 */2 * * * ?")
    public void execute(){
        //查询未发货订单，当订单数量大于一定数量 则向前端推送数据
        int nums = orderServiceImpl.waitSendingOrderNums();
        if(nums>=5){
            template.convertAndSend("/topic/getResponse", "您当前有超过"+nums+"笔订单待发货，请合理安排发货时间");
        }
    }

}
